package com.example.studentinfo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class NewStudent extends AppCompatActivity {
    DbHelper dbHelper;
    Button btn_confirm;
    String xb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_student);
        setTitle("AddStudentInfo");
        dbHelper=new DbHelper(NewStudent.this,"MyDataBase",2);
        btn_confirm = findViewById(R.id.btn_confirm);
        setlisener();
    }

    /**
     * 设置监听
     */
    public void setlisener(){
        RadioGroup radgroup = findViewById(R.id.radioGroup);

        //String xb;因为实在匿名内部类的函数里面所以不能用其它函数的内部变量只能用类的属性变量。
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText et_xm = findViewById(R.id.et_xm);
                EditText et_xh = findViewById(R.id.et_xh);
                EditText et_bj = findViewById(R.id.et_bj);
                EditText et_zy = findViewById(R.id.et_zy);
                EditText et_cj = findViewById(R.id.et_cj);
                String xm = et_xm.getText().toString();
                RadioButton radbtn=findViewById(radgroup.getCheckedRadioButtonId()) ;
                xb=radbtn.getText().toString();
                String xh = et_xh.getText().toString();
                String bj = et_bj.getText().toString();
                String zy = et_zy.getText().toString();
                String cj = et_cj.getText().toString();
                if (TextUtils.isEmpty(xm)||TextUtils.isEmpty(xh)){
                    Toast.makeText(NewStudent.this,"学号或者姓名不可为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra("xm",xm);
                intent.putExtra("xb",xb);
                intent.putExtra("xh",xh);
                intent.putExtra("bj",bj);
                intent.putExtra("zy",zy);
                intent.putExtra("cj",cj);
                setResult(RESULT_OK,intent);
                finish();
            }
        });
    }
}